package ChessEngine;

import java.util.HashMap;
import java.util.Random;

import boardData.Board;

public class ZobristHashRandomNumbers {
	//gemeint ist, kleine true, große false
	private static final int ROCHADE_1 = 0;
	//gemeint ist: kleine true, große true;
	private static final int ROCHADE_2 = 1;
	//gemeint ist: kleine false, große false;
	private static final int ROCHADE_3 = 2;
	//geimeint ist: kleine false, große true
	private static final int ROCHADE_4 = 3;
	//problem: wie identifiezier ich die einzelnen moeglickeiten??
	//Erste Zahl ist nr des Felds, zweite die nr der Figur
	private static HashMap<Integer, HashMap<Integer,Long>> PIECES; // [piece][square]
	//erster wert große Rochade
	private static  HashMap<Integer, Long>W_CASTLING; // Four different castling setups
	private static HashMap<Integer, Long> B_CASTLING; // both ways, short, long and none
	//nummer des bauernfeldes
	private static HashMap<Integer, Long> EN_PASSENT ; // En passant
	private static long SIDE_TO_MOVE; // Used for changing sides

	public ZobristHashRandomNumbers(){
		Random r = new Random();
		
		//seite die am zug ist
		SIDE_TO_MOVE = r.nextLong();
		
		// position des feldes und figur
		for(int i=21;i<98;i++){
			if(i % 10 == 0 || i%10 == 9){
				continue;
			}
			HashMap<Integer, Long> randomNumbers = new HashMap<Integer, Long>();
			randomNumbers.put(Board.BLACK_BISHOP,r.nextLong());
			randomNumbers.put(Board.BLACK_KING,r.nextLong());
			randomNumbers.put(Board.BLACK_KNIGHT,r.nextLong());
			randomNumbers.put(Board.BLACK_PAWN,r.nextLong());
			randomNumbers.put(Board.BLACK_QUEEN,r.nextLong());
			randomNumbers.put(Board.BLACK_ROOK,r.nextLong());
			
			randomNumbers.put(Board.WHITE_BISHOP,r.nextLong());
			randomNumbers.put(Board.WHITE_KING,r.nextLong());
			randomNumbers.put(Board.WHITE_KNIGHT,r.nextLong());
			randomNumbers.put(Board.WHITE_PAWN,r.nextLong());
			randomNumbers.put(Board.WHITE_QUEEN,r.nextLong());
			randomNumbers.put(Board.WHITE_ROOK,r.nextLong());
			PIECES.put(i,randomNumbers);
		}
		
		//Rochademoeglichkeiten
		for(int i=0;i<4;i++){
			W_CASTLING.put(i,r.nextLong());
		}
		
		for(int i=0;i<4;i++){
			B_CASTLING.put(i, r.nextLong());
		}
		
		//en passent
		EN_PASSENT.put(31, r.nextLong());
		EN_PASSENT.put(32, r.nextLong());
		EN_PASSENT.put(33, r.nextLong());
		EN_PASSENT.put(34, r.nextLong());
		EN_PASSENT.put(35, r.nextLong());
		EN_PASSENT.put(36, r.nextLong());
		EN_PASSENT.put(37, r.nextLong());
		EN_PASSENT.put(38, r.nextLong());
		
		EN_PASSENT.put(81, r.nextLong());
		EN_PASSENT.put(82, r.nextLong());
		EN_PASSENT.put(83, r.nextLong());
		EN_PASSENT.put(84, r.nextLong());
		EN_PASSENT.put(85, r.nextLong());
		EN_PASSENT.put(86, r.nextLong());
		EN_PASSENT.put(87, r.nextLong());
		EN_PASSENT.put(88, r.nextLong());
	}
	
	public long getEnPassentRandom(int index){
		if(EN_PASSENT.containsKey(index)){
			return EN_PASSENT.get(index);
		}
		return -1;
	}
	
	public long getWhiteCastlingRandom(int index){
		if(W_CASTLING.containsKey(index)){
			return W_CASTLING.get(index);
		}
		return -1;
	}
	
	public long getBlackCastlingRandom(int index){
		if(B_CASTLING.containsKey(index)){
			return B_CASTLING.get(index);
		}
		return -1;
	}
	
	public long getSideToMoveRandom(int index){
		return SIDE_TO_MOVE;
	}
	
	public long getFieldPieceRandom(int field, int piece){
		if(PIECES.containsKey(field)){
			if(PIECES.get(field).containsKey(piece)){
				return PIECES.get(field).get(piece);
			}
			return -1;
		}
		return -1;
	}
}
